package com.zzg.util;


import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间格式转换类
 * 需要配置
 */
public class TransformDate implements Converter<String, Date> {

    @Override
    public Date convert(String source) {
        System.out.println("时间转化方法执行了");
        System.out.println(source);
        if(source != null) {
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date date = (Date) f.parse(source);
                System.out.println("转化完成");
                return date;

            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}

